import axios from 'axios'
import './index'
const noticeBaseUrl = import.meta.env.VITE_BASE_URL
function Http({ url, method = 'get' }) {
  return axios({
    url: noticeBaseUrl + url,
    method
  })
}
function Post({ url, method = 'post', user_id, notice_title, notice_content }) {
  return axios({
    url: noticeBaseUrl + url,
    method,
    data: {
      user_id,
      notice_title,
      notice_content
    }
  })
}
function Put({ url, method = 'put', notice_status }) {
  return axios({
    url: noticeBaseUrl + url,
    method,
    data: {
      notice_status
    }
  })
}
// 获取所有分页公告
const getnoticesHttp = (page, size) => {
  return Http({
    url: `/notices?page=${page}&size=${size}`
  })
}
// 获取单个公告
const getOnenoticeHttp = (id) => {
  return Http({
    url: `/notices/${id}`
  })
}
// 添加公告
const addnoticePost = (user_id, notice_title, notice_content) => {
  return Post({
    url: '/notices',
    user_id,
    notice_title,
    notice_content
  })
}
// 软删除公告
const delnoticePut = (id, notice_status) => {
  return Put({
    url: `/notices/${id}`,
    notice_status
  })
}

// 导出公告请求模块
export { getnoticesHttp, getOnenoticeHttp, addnoticePost, delnoticePut }
